package com.danbay.cloud.account.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.danbay.cloud.account.dto.ResourceDto;
import com.danbay.cloud.account.entity.Resource;
import com.danbay.cloud.account.mapper.ResourceMapper;
import com.danbay.cloud.account.service.api.IResourceService;
import com.danbay.cloud.base.constants.ResourceType;
import com.danbay.framework.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author SJG
 *         2018/1/11.
 */
@Service
public class ResourceService implements IResourceService {

    @Autowired
    private ResourceMapper resourceMapper;

    /**
     * 取所有菜单
     *
     * @return 菜单列表
     */
    @Override
    public List<ResourceDto> allMenus() {
        return BeanUtils.convert(resourceMapper.selectList(new EntityWrapper<>(Resource.builder().type(ResourceType.MENU.value()).build())), ResourceDto.class);
    }

    /**
     * 取所有按钮
     * @return 按钮列表
     */
    @Override
    public List<ResourceDto> allButtons() {
        return BeanUtils.convert(resourceMapper.selectList(new EntityWrapper<>(Resource.builder().type(ResourceType.BUTTON.value()).build())), ResourceDto.class);
    }
}
